using System;
using System.Diagnostics;
using Android.App;
using Android.Content;
using HalalCheck.Droid.Share;
using HalalCheck.Utils;
using Xamarin.Forms;
using Xamarin.Social;
using Xamarin.Social.Services;
using Xamarin.Auth;

[assembly: Dependency(typeof(ShareImplementation))]
namespace HalalCheck.Droid.Share
{
    public class ShareImplementation : IShare, IShareProduct
    {

        public static void Init()
        {
        }

        public void ShareStatus(string status)
        {
            ShareOnService(status);
        }

        public void ShareLink(string title, string status, string link)
        {
            ShareOnService(status, title, link);
        }

        private void ShareOnService(string status, string title = "", string link = "")
        {
            var intent = new Intent(global::Android.Content.Intent.ActionSend);
            intent.PutExtra(global::Android.Content.Intent.ExtraText, String.Format("{0} - {1}", status ?? string.Empty, link ?? string.Empty));
            intent.PutExtra(global::Android.Content.Intent.ExtraSubject, title ?? string.Empty);
            intent.SetType("text/plain");
            intent.SetFlags(ActivityFlags.ClearTop);
            intent.SetFlags(ActivityFlags.NewTask);
            Android.App.Application.Context.StartActivity(intent);
        }

        public void ShareFB()
        {

            // 1. Create the service
            var facebook = new FacebookService
         {
             ClientId = "220815371312174",
             ClientSecret = "495e348ccf0fb871fe7782ef54b7ec6f",
             RedirectUrl = new Uri("https://dl.dropboxusercontent.com/u/4492418/redirect.html/"),
             Scope = "public_actions"
         };

          
            // 2. Create an item to share
            var item = new Item { Text = "oihoihioh." };
            // item.Links.Add(new Uri("http://github.com/xamarin/xamarin.social"));

            // 3. Present the UI on Android
            var shareIntent = facebook.GetShareUI(Forms.Context as Activity, item, result =>
            {
                // result lets you know if the user shared the item or canceled
                Debug.Write(result);
            });
 
            Debug.WriteLine((Forms.Context as Activity).Class.CanonicalName);
            shareIntent.SetFlags(ActivityFlags.NewTask);

            Forms.Context.StartActivity(shareIntent);
            //   StartActivityForResult(, 42);*/
        }

    }
}
